<template>
  <div class="login-container">
    <el-card class="login-card">
      <div class="login-header">
        <h2>账号登录</h2>
      </div>
      <div class="login-form">
        <el-form
          :model="loginForm"
          ref="loginForm"
          :rules="rules"
          label-width="80px"
        >
          <el-form-item label="用户名" prop="username">
            <el-input
              v-model="loginForm.username"
              placeholder="请输入用户名"
              prefix-icon="el-icon-user"
            ></el-input>
          </el-form-item>
          <el-form-item label="密码" prop="password">
            <el-input
              type="password"
              v-model="loginForm.password"
              placeholder="请输入密码"
              prefix-icon="el-icon-lock"
            ></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="login" class="login-btn"
              >登录</el-button
            >
          </el-form-item>
        </el-form>
      </div>
    </el-card>
  </div>
</template>

<script>
export default {
  name: "Login",
  data () {
    return {
      loginForm: {
        username: "",
        password: "",
      },
      rules: {
        username: [
          { required: true, message: "请输入您的用户名", trigger: "blur" },
        ],
        password: [
          { required: true, message: "请输入您的密码", trigger: "blur" },
        ],
      },
    }
  },
  methods: {
    login () {
      this.$refs.loginForm.validate((valid) => {
        if (valid) {
          // 编程式导航，使用replace方法跳转(目的不保存该登录页的历史记录)
          this.$router.replace('/home')
          this.$store.commit('setBreakList', '助力活动')
        }
      })
    },
  },
};
</script>

<style>
.login-container {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background-image: linear-gradient(
      206deg,
      rgba(72, 45, 45, 0.46) 0%,
      rgba(72, 45, 45, 0.46) 14.286%,
      rgba(102, 42, 45, 0.46) 14.286%,
      rgba(102, 42, 45, 0.46) 28.572%,
      rgba(131, 39, 44, 0.46) 28.572%,
      rgba(131, 39, 44, 0.46) 42.858%,
      rgba(161, 36, 44, 0.46) 42.858%,
      rgba(161, 36, 44, 0.46) 57.144%,
      rgba(191, 33, 43, 0.46) 57.144%,
      rgba(191, 33, 43, 0.46) 71.43%,
      rgba(220, 30, 43, 0.46) 71.43%,
      rgba(220, 30, 43, 0.46) 85.716%,
      rgba(250, 27, 42, 0.46) 85.716%,
      rgba(250, 27, 42, 0.46) 100.002%
    ),
    linear-gradient(
      127deg,
      rgb(254, 36, 223) 0%,
      rgb(254, 36, 223) 14.286%,
      rgb(227, 44, 210) 14.286%,
      rgb(227, 44, 210) 28.572%,
      rgb(201, 52, 198) 28.572%,
      rgb(201, 52, 198) 42.858%,
      rgb(174, 60, 185) 42.858%,
      rgb(174, 60, 185) 57.144%,
      rgb(147, 67, 172) 57.144%,
      rgb(147, 67, 172) 71.43%,
      rgb(121, 75, 160) 71.43%,
      rgb(121, 75, 160) 85.716%,
      rgb(94, 83, 147) 85.716%,
      rgb(94, 83, 147) 100.002%
    );
}

.login-card {
  width: 400px;
  margin-top: 50px;
  border-radius: 10px;
  background-color: rgba(255, 255, 255, 0.6);
}

.login-header {
  text-align: center;
  padding: 20px;
}

.login-form {
  padding: 20px;
}

.login-btn {
  width: 100%;
  height: 40px;
  border-radius: 20px;
}
</style>
